import CryptoJS from 'crypto-js';
	interface Cryption {
		encrypt(data: string, key: string): string;
		decrypt(encryptedData: string, key: string): string;
	}
	const cryption: Cryption = {
		encrypt(data: string, key: string): string {
			// 使用 AES/ECB/PKCS5Padding 加密
			const encryptedData = CryptoJS.AES.encrypt(data, CryptoJS.enc.Utf8.parse(key), {
				mode: CryptoJS.mode.ECB,
				padding: CryptoJS.pad.Pkcs7,
			});

			// 将加密后的数据转换为Base64字符串
			return encryptedData.toString();
		},
		decrypt(encryptedData: string, key: string): string {
			const decryptedKey = CryptoJS.enc.Utf8.parse(key);

			const decryptedBytes = CryptoJS.AES.decrypt(encryptedData, decryptedKey, {
				mode: CryptoJS.mode.ECB,
				padding: CryptoJS.pad.Pkcs7,
			});

			const decryptedText = decryptedBytes.toString(CryptoJS.enc.Utf8);

			return decryptedText;
		},
	};

export default cryption;
